﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class LoginForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        
        string connectionString = "Data Source=csd.columbusstate.edu;Initial Catalog=6118_fa12_TeamC;User ID=student;Password=cscpsc12";

        using (var connection = new SqlConnection(connectionString))
        using (var command = new SqlCommand("AddNewCustomer", connection)
        {
            CommandType = CommandType.StoredProcedure
        })
        {
            SqlParameter username = new SqlParameter("@username", SqlDbType.NVarChar, 50);
            username.Value = txtUserName.Text.ToString();
            command.Parameters.Add(username);

            SqlParameter firstName = new SqlParameter("@firstname", SqlDbType.NVarChar, 50);
            firstName.Value = txtFirstName.Text.ToString();
            command.Parameters.Add(firstName);

            SqlParameter lastName = new SqlParameter("@lastname", SqlDbType.NVarChar, 50);
            lastName.Value = txtLastName.Text.ToString();
            command.Parameters.Add(lastName);

            SqlParameter address = new SqlParameter("@address", SqlDbType.NVarChar, 50);
            address.Value = txtAddress.Text.ToString();
            command.Parameters.Add(address);

            SqlParameter city = new SqlParameter("@city", SqlDbType.NVarChar, 50);
            city.Value = txtCity.Text.ToString();
            command.Parameters.Add(city);

            SqlParameter state = new SqlParameter("@state", SqlDbType.NVarChar, 50);
            state.Value = ddState.Text.ToString();
            command.Parameters.Add(state);

            SqlParameter zip = new SqlParameter("@zip", SqlDbType.NVarChar, 50);
            zip.Value = txtZip.Text.ToString();
            command.Parameters.Add(zip);

            SqlParameter password = new SqlParameter("@pwd", SqlDbType.NVarChar, 50);
            password.Value = txtPwd.Text.ToString();
            command.Parameters.Add(password);

            try
            {
                connection.Open();
                command.ExecuteNonQuery();
                lblMsg.Text = "User Registration successful";
            }
            catch (SqlException ex)
            {
                string errorMessage = "Error in registering user";
                errorMessage += ex.Message;
                throw new Exception(errorMessage);

            }
            finally
            {
                connection.Close();
            }
        }  

    }
}
